import { config } from "process";
import Request from "./request";
import { BASE_URL, TIME_OUT } from "./request/config"

const request = new Request({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  //标志当前是否正在刷洗token
  interceptors: {
    requestInterceptors: (config: any) => {
      const token = localStorage.getItem('token') || ""
      if (token) {
        config.headers.Authorization = token
      }
      console.log('请求拦截');
      return config
    },
    requestInterceptorsCatch: (err) => {
      console.log("请求失败的拦截");
      if (err.response.status === 404) alert("Not Found 404");
      return err;
    },
    responseInterceptors: (res) => {
      console.log("响应成功的拦截");
      return res.data;
    },
    responseInterceptorsCatch: (err) => {
      console.log("响应失败的拦截");
      return err;
    },
  }
})
export default request